import { routerRedux } from 'dva/router';
import { effects } from 'redux-saga';
import { getMoneyList } from '../services/money';

export default {
    namespace: "money",

    state: {
        RehargeItem: {
            list: []
        },
    },
    effects: {
        *getMoneyList({ payload }, { call, put }) {
            const res = yield call(getMoneyList, payload)
            const { status, message, result } = res;
            console.log("result", result)
            if (status == 0) {
                yield put({
                    type: 'updateState',
                    payload: {
                        RehargeItem: result
                    }
                })
            } else {
                message.error(message)
            }
        }
    },
    reducers: {
        updateState(state, { payload }) {
            return {
                ...state,
                ...payload
            }
        }
    },
    subscriptions: {
        setup({ dispatch, history }) {
            history.listen(location => {
                if (location.pathname === '/charge/money') {
                    dispatch({
                        type: 'getMoneyList',
                        payload: {
                            ...location.query
                        }
                    })
                }
            })
        }
    }
}